package architect;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

import static java.util.concurrent.Executors.newFixedThreadPool;

/**
 * @title: BasicFuture
 * @description:
 * @author: guan.xin
 * @create: 2021-09-25 09:32
 * @since: JDK8
 */
public class BasicFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService es = newFixedThreadPool(10);
        Future<Integer> f = es.submit(() -> {
            // 长时间的异步计算
            // ……
            // 然后返回结果
            Thread.sleep(3000L);

            return 100;
        });
        System.out.println(f.get());
    }
}
